fix: sync default tags to native layer#5214
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5214 +/- ##
=======================================
Coverage 74.14% 74.14%
=======================================
Files 506 506
Lines 18292 18295 +3
Branches 3576 3578 +2
=======================================
+ Hits 13562 13565 +3
Misses 3859 3859
Partials 871 871 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| // but native crashes are captured and uploaded by the native SDK without going through that pipeline. | ||
| // Forward them to the scope observer so the native layer attaches them to crash reports. | ||
| // Bypassing the .NET scope keeps scope.Tags identical between native and non-native apps. | ||
| if (options is { EnableScopeSync: true, ScopeObserver: { } observer } && options.DefaultTags.Count > 0) |
There was a problem hiding this comment.
It looks like this would work in Global mode (where there is only one scope).
I'm wondering what would happen for an Asp.Net Core application that's compiled AOT. I believe we enable Sentry Native for AOT compiled applications - but I imagine Sentry Native doesn't have any notion of an 'AsyncLocal' scope stack so we effectively end up with Global scopes (and no scope observer in any case) for native events in Asp.Net Core apps compiled AOT. So that would (probably) work as expected as well (i.e. anything you put in the Default tags would end up on all native events in Asp.Net Core AOT apps).
It might be worth testing that scenario just to check (or getting an LLM to build a little test app to check that - can't really add it to our test suite as we have no easy way to test AOT yet - so it would just be a sanity check).
| // but native crashes are captured and uploaded by the native SDK without going through that pipeline. | ||
| // Forward them to the scope observer so the native layer attaches them to crash reports. | ||
| // Bypassing the .NET scope keeps scope.Tags identical between native and non-native apps. | ||
| if (options is { EnableScopeSync: true, ScopeObserver: { } observer } && options.DefaultTags.Count > 0) |
There was a problem hiding this comment.
Can DefaultTags.Count > 0 be merged into the pattern match to simplify this?
jamescrosswell
left a comment
There was a problem hiding this comment.
Generally LGTM... two comments, would be good to check the ASP.NET Core behaviour before merging, just to be sure we're not breaking anything there (seems unlikely but that could be famous last words).
Honestly I'm not sure why Default Tags vs putting some tags on the root scope - seems like either would have worked 🤷🏻
Came up through and resolves getsentry/sentry-unity#2668
The Problem
When a user sets
DefaultTagson the options, these tags do not make it to native events from Android or iOS. This is not only an issue for Unity but affects C# Android and iOS app as well.The comment seems to be out of date and prior to the addition of the extensive native support the SDK has now.
Context
When a user sets the
DefaultTagson the options, in the regular processing pipeline, these get applied by theEnricheron each individual event.sentry-dotnet/src/Sentry/Internal/Enricher.cs
Line 104 in af4ebc3
I don't know what the grand design here was, and why tags are not getting applied to the scope instead. Maybe this comes from one of the other integrations, or behaviour outside of having a
GlobalScope? If not, we could move it out of theEnricherin general. Happy to follow up on this if that's the case.Proposal
During initialization, and if scope sync is enabled, and if there is a
ScopeObserver, we set those tags, making them available on the native layer. The regular flow inside the C# processing stays preserved.Sample events taken from the Unity SDK with
options.DefaultTags.Add("my", "tag");: